/*
 * Copyright 2005-2006 the original authors and www.opengoss.org community.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */ 
package org.opengoss.web.service.meta;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

import org.opengoss.web.service.URIPattern;
import org.opengoss.web.service.annotation.WMethod;
/**
 * Annotaion style web method metadata.
 *
 * @author Ery Lee(ery.lee@gmail.com)
 * @version 1.0 2006-11-20
 * @since 1.0
 */
public class AnnoWMethodMeta implements IWMethodMeta {

	private WMethod wmAnnotation;

	private Method method;

	public AnnoWMethodMeta(WMethod wmAnno, Method method) {
		this.wmAnnotation = wmAnno;
		this.method = method;
	}
	/*
	 * (non-Javadoc)
	 * @see org.opengoss.web.service.meta.IWMethodMeta#getMethod()
	 */
	public Method getMethod() {
		return method;
	}
	/*
	 * (non-Javadoc)
	 * @see org.opengoss.web.service.meta.IWMethodMeta#getUriPattern()
	 */
	public URIPattern getUriPattern() {
		return new URIPattern(wmAnnotation.uri());
	}
	/*
	 * (non-Javadoc)
	 * @see org.opengoss.web.service.meta.IWMethodMeta#getMethodType()
	 */
	public String getMethodType() {
		return wmAnnotation.type().toString();
	}
	/*
	 * (non-Javadoc)
	 * @see org.opengoss.web.service.meta.IWMethodMeta#getParamMetas()
	 */
	public IWParamMeta[] getParamMetas() {
		Annotation[][] annotations = method.getParameterAnnotations();
		IWParamMeta[] paramMetas = new AnnoWParamMeta[annotations.length];
		for (int i = 0; i < annotations.length; i++) {
			paramMetas[i] = new AnnoWParamMeta(annotations[i][0]);
		}
		return paramMetas;
	}

}
